//
//  BTEProductFoureView.swift
//  BTE
//
//  Created by Mike Zhang on 2025/8/5.
//

import UIKit

class BTEProductFoureView: UIView {

    var clickArea:(()->())?
    
    var clickEnum:(()->())?
    
    var clickChoise:((Int)->())?
    
    let list = BTEBaseTableView.init(frame: .zero, style: .plain)
    
    let button = UIButton.init()
    
    var model: [BTECarnepalaeoglafewfwcioewelogyNetModel]? {
        didSet {
            guard let m = model else {
                return
            }
            list.reloadData()
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        button.setTitle(title: BTELanguageManager.shared.localizedString(forKey: "Next"))
        button.setBackgroundColor(UIColor.colorWithHex("#39B4E6")!)
        button.setFont(UIFont.systemFont(ofSize: 18, weight: .bold))
        button.setTitleColor(.white)
        button.roundCorners(.allCorners, radius: 25)
        button.layer.borderWidth = 2
        button.layer.borderColor = UIColor.colorWithHex("#6C2724")?.cgColor
        addSubview(button)
        button.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(38)
            make.bottom.equalToSuperview().offset(-34)
            make.height.equalTo(50)
        }
    
        list.backgroundColor = .clear
        addSubview(list)
        list.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalToSuperview()
            make.bottom.equalTo(button.snp.top)
        }
        list.delegate = self
        list.dataSource = self
        list.separatorStyle = .none
        
        list.register(BTEUserContactTableViewCell.self, forCellReuseIdentifier: BTEUserContactTableViewCell.indetification)
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
  
  

}


extension BTEProductFoureView: UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return (model ?? []).count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if let m = model?[indexPath.row] {
            guard let ce = tableView.dequeueReusableCell(withIdentifier: BTEUserContactTableViewCell.indetification, for: indexPath) as? BTEUserContactTableViewCell else {
                return UITableViewCell()
            }
            ce.model = m
            
            ce.action = {[weak self] in
                self?.list.reloadRows(at: [indexPath], with: .none)
            }
            
            ce.choiseUser = {[weak self] in
                self?.clickChoise?(indexPath.row)
            }
            
            return ce
        }
        return UITableViewCell()
    }
    
    
  
    
    
}


